/**
 * 屏幕计算相关方法
 */

/**
 * 根据canvas宽高和屏幕宽高计算出canvas的等比全部展示的宽高
 */
export const getScreen = ({
    canvasScreen,
    screen
}: {
    canvasScreen: {
        width: number,
        height: number
    },
    screen: {
        width: number,
        height: number
    }
}) => {
    // canvas宽高比
    const canvasRadio = canvasScreen.width / canvasScreen.height;
    const screenRadio = screen.width / screen.height;

    // 若canvas的等比比屏幕的等比大，则以canvas的等比为主
    if (canvasRadio > screenRadio) {
        let height = screen.width / canvasRadio;
        return {
            width: screen.width,
            height,
            top: ( screen.height - height) / 2,
            left: 0,
            zoom: screen.width / canvasScreen.width,
        };
    } else {
        let width = screen.height * canvasRadio;
        return {
            width,
            height: screen.height,
            top: 0,
            left: (screen.width - width) / 2,
            zoom: width / canvasScreen.width,
        };
    }
}